#include "CellSpacePartition3D.hpp"
#include "../utils/Utils.hpp"


using namespace klasPhysics;
using namespace std;
using namespace irr;

// ======================= Constructors ========================
CellSpacePartition3D::CellSpacePartition3D(Vector3D dim, Vector3D num_cells, int MaxEntities):m_Dimensions(dim),
																								m_NumCells(num_cells)
{
	
	m_CellArray.resize(m_NumCells.x*m_NumCells.y*m_NumCells.z);
	m_CellSize = m_Dimensions / m_NumCells;
	for(int i = 0; i < m_NumCells.x; ++i)
		for(int j = 0; j < m_NumCells.y; ++j)
			for(int k = 0; k < m_NumCells.z; ++k)
			{
				m_CellArray[Index3D(i,j,k, m_NumCells.x, m_NumCells.y)] = Box3D(Vector3D(i*m_CellSize.x, j*m_CellSize.y, k*m_CellSize.z), m_CellSize);
			
			}
}

void CellSpacePartition3D::RenderCells(irr::scene::ISceneManager *s_mgr)
{
	for(int i = 0; i < m_NumCells.x*m_NumCells.y*m_NumCells.z; i++)
	{
		m_CellArray[i].RenderBox = s_mgr->addCubeSceneNode(m_CellArray[i].m_BBox.Dimensions().x);
		
		m_CellArray[i].RenderBox->setPosition(core::vector3df(m_CellArray[i].m_BBox.Pos().x,
																m_CellArray[i].m_BBox.Pos().y,
																m_CellArray[i].m_BBox.Pos().z));

		m_CellArray[i].RenderBox->setMaterialFlag(video::EMF_LIGHTING, false);
		m_CellArray[i].RenderBox->setMaterialFlag(video::EMF_WIREFRAME, true);
	}
}
	


	